<template>
  <div style="width: 100%;height: 500px;padding-top:0;margin: 0 ">
    <div class="pageheader">
      <div class="pageheader-1">
        <i class="el-icon-user-solid"></i><label>慢性病报销记录查询</label>
      </div>
      <div style="height: 100%;position: absolute;top: 20px;left: 350px">
        <el-form :model="input" ref="key">
        <el-input
          style="width: 200px;position: absolute;top: 5px;left: 0px"
          size="small"
          placeholder="请输入报销单号"
          suffix-icon="el-icon-search"
          maxlength="20"
          v-model="input.input3">
        </el-input>
        <el-button type="primary" class="searchbtn" @click="find('key')" plain>查询</el-button>
        </el-form>
      </div>
    </div>
    <el-table
      :data="tableData"
      border
      style="width: 100%;height: 80%">

      <el-table-column
        prop="baoxiaoid"
        label="报销单号">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="money"
        label="报销金额">
      </el-table-column>
      <el-table-column
        prop="chengid"
        label="身份证号">
      </el-table-column>
      <el-table-column
        prop="status"
        label="状态">
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作">
        <template slot-scope="scope">
          <el-button v-show="list[1].children[5].find && scope.row.status === '审核中'" type="primary" @click="handleClick(scope.row)" >审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--审核-->
    <el-dialog title="添加" @close="this.reload" :visible.sync="dialogFormVisible">
      <el-form :rules="rules" :model="form" ref="addAction">
        <el-form-item prop="baoxiaoid" label="报销单号" :label-width="formLabelWidth">
          <el-input :disabled="true" v-model="form.baoxiaoid" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item prop="name" label="姓名" :label-width="formLabelWidth">
          <el-input :disabled="true" v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item prop="chengid" label="身份证号" :label-width="formLabelWidth">
          <el-input :disabled="true" v-model="form.chengid" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item prop="money" label="报销金额" :label-width="formLabelWidth">
          <el-input :disabled="true" v-model="form.money" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="edit ('addAction')">不通过</el-button>
        <el-button type="primary" @click="add ('addAction')">通过</el-button>
      </div>
    </el-dialog>
    <!--分页 -->
    <div class="pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        page-size="5"
        :total="total"
        @current-change="page">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  inject: ['reload', 'list'],
  methods: {
    // 查询功能
    find (key) {
      const _this = this
      if (this.input.input3 !== '') {
        axios.get('http://localhost:8088/findBaoxiaoAll/' + this.input.input3).then(function (resp) {
          _this.tableData = resp.data
          _this.total = 1
        })
      } else {
        this.reload()
      }
    },
    // 添加
    add (addAction) {
      const _this = this
      this.$refs[addAction].validate((valid) => {
        axios.post('http://localhost:8088/saveBaoxiao1', this.form).then(function (resp) {
          _this.$message({
            message: '已审核！',
            type: 'success'
          })
          _this.reload()
        })
      })
    },
    // 修改
    edit (addAction) {
      const _this = this
      this.$refs[addAction].validate((valid) => {
        axios.post('http://localhost:8088/saveBaoxiao2', this.form).then(function (resp) {
          _this.$message({
            message: '已审核！',
            type: 'success'
          })
          _this.reload()
        })
      })
      this.reload()
    },
    // 读取当前行的数据
    handleClick (row) {
      this.form = row
      this.dialogFormVisible = true
    },
    // 删除
    opendelete (row) {
      this.openelete = true
      this.form = row
    },
    delete_data () {
      axios.post('http://localhost:8088/deleteArea/' + this.form.id).then(function (resp) {
      })
      this.$message({
        message: '删除成功！',
        type: 'success'
      })
      this.reload()
    },
    // 查询
    findById (search) {
      this.$refs[search].validate((valid) => {
        const _this = this
        if (_this.input.input3 !== '') {
          axios.get('http://localhost:8088/findByDepid/' + _this.input.input3).then(function (resp) {
            if (resp.data === null) {
              _this.tableData = resp.data
              _this.total = 1
            } else {
              alert('啥也没找到')
              _this.reload()
            }
          })
        } else {
          this.reload()
        }
      })
    },
    // 分页模块
    page (currentpage) {
      const _this = this
      axios.get('http://localhost:8088/findBaoxiaoAll/' + currentpage + '/5').then(function (resp) {
        console.log(resp.data)
        _this.tableData = resp.data.content
        _this.total = resp.data.totalElements
      })
    }
  },
  // 接受后台数据
  created () {
    const _this = this
    axios.get('http://localhost:8088/findBaoxiaoAll/1/5').then(function (resp) {
      _this.tableData = resp.data.content
      _this.total = resp.data.totalElements
    })
  },
  //  数据绑定
  data () {
    return {
      total: null,
      input: {
        input3: ''
      },
      tableData: null,
      dialogFormVisible: false,
      editdep: false,
      openelete: false,
      form: {
        id: '',
        baoxiaoid: '',
        name: '',
        money: '',
        chengid: '',
        status: ''
      },
      e_form: {
        id: '',
        areaid: '',
        arename: '',
        level: ''
      },
      formLabelWidth: '100px',
      rules: {
        baoxiaoid: [
          { required: true, message: '请输入报销单号', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        money: [
          { required: true, message: '请输入报销金额', trigger: 'blur' }
        ],
        chengid: [
          { required: true, message: '请输入身份证号', trigger: 'blur' }
        ]
      }
    }
  }
}
</script>
